module.exports = {
  description: '新建组件',
  prompts: [
    {
      type: 'input',
      name: 'name',
      message: '组件名称',
      validate (value) {
        return !value.trim() ? '请输入组件名称' : true
      }
    },
    {
      type: 'input',
      name: 'url',
      message: '路径',
      default: 'components'
    },
    {
      type: 'input',
      name: 'filename',
      message: '文件名',
      default: 'index'
    },
    {
      type: 'checkbox',
      name: 'blocks',
      message: '请选择模块',
      choices: [
        {
          name: '<template>',
          value: 'template',
          checked: true
        },
        {
          name: '<script>',
          value: 'script',
          checked: true
        },
        {
          name: '<style>',
          value: 'style',
          checked: true
        }
      ],
      validate (value) {
        if (value.indexOf('script') === -1 && value.indexOf('template') === -1) {
          return '至少拥有script或template模块'
        }
        return true
      }
    }
  ],
  actions: data => {
    return [
      {
        type: 'add',
        path: `src/{{url}}/${data.filename === 'index' ? '{{name}}' : ''}/{{filename}}.vue`,
        templateFile: 'plop-templates/component/index.hbs',
        data: {
          name: '{{name}}',
          template: data.blocks.includes('template'),
          script: data.blocks.includes('script'),
          style: data.blocks.includes('style')
        }
      }
    ]
  }
}
